# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import pymysql

class ZhaobiaoPipeline:
    def __init__(self):
        self.myconn=pymysql.Connection(
            host='localhost',
            port=3306,
            user='root',
            password='123456',
            database='zhaobiao',
            charset='utf8'
        )

    def process_item(self, item, spider):

        cs=self.myconn.cursor()
        sql_column=','.join([key for key in item.keys()])
        sql_value=','.join(['"%s"' % item[key] for key in item.keys()])
        sql_str='insert into t_zhaobiao(%s) value(%s)' % (sql_column,sql_value)
        cs.execute(sql_str)
        self.myconn.commit()
        return item
